import pandas as pd
import json
import os

# 获取当前脚本所在目录
base_dir = os.path.dirname(os.path.abspath(__file__))
json_path = os.path.join(base_dir, 'baidu_news.json')
excel_path = os.path.join(base_dir, '百度新闻标题.xlsx')

# 读取并解析JSON数据
with open(json_path, 'r', encoding='utf-8') as f:
    data = json.load(f)

# 提取新闻标题列表
news_titles = data['news_titles']

# 创建DataFrame并导出Excel
df = pd.DataFrame(news_titles, columns=['热点新闻标题'])
df.to_excel(excel_path, index=False)

print(f"Excel文件已生成：{excel_path}")
